<template>
	<view class="container">
		<uni-card title="基本信息">
			<uni-forms ref="uForm" :modelValue="formData" label-width="120">
				<uni-forms-item label="商品名称" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.product_name"></u--input>
				</uni-forms-item>
				<uni-forms-item label="团购id">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.tuan_dy_product_id"></u--input>
				</uni-forms-item>
				<uni-forms-item label="商品分类" required>
					<uni-data-select v-model="formData.class_id" :localdata="classfiyArr" @change="classChange"
						:clear="false"></uni-data-select>
				</uni-forms-item>
				<uni-forms-item label="抖音品类" required>
					<uni-data-select v-model="formData.category_id_one" :localdata="range1" @change="selectChange1"
						:clear="false"></uni-data-select>
					<uni-data-select v-model="formData.category_id_two" :localdata="range2" @change="selectChange2"
						:clear="false" v-if="formData.category_id_one" style="margin-top: 10rpx;"></uni-data-select>
					<uni-data-select v-model="formData.category_id_three" :localdata="range3" @change="selectChange3"
						:clear="false" v-if="formData.category_id_two" style="margin-top: 10rpx;"></uni-data-select>
					<text
						style="margin-top: 10rpx;color: red;font-size: 24rpx;">请务必检查抖音品类三级选项是否全部勾选，出现（无选项）字样的选项则无需勾选</text>
				</uni-forms-item>
				<!-- <uni-forms-item label="商品类型" required>
					<uni-data-checkbox v-model="formData.product_type" :localdata="product_type"
						@change="statusChange"></uni-data-checkbox>
				</uni-forms-item> -->
				<uni-forms-item label="配送方式" required>
					<uni-data-checkbox v-model="formData.delivery_method" :localdata="delivery_method"
						@change="deliverChange" :multiple="true"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="商品规格">
					<uni-data-checkbox v-model="formData.product_spec" :localdata="product_spec"
						@change="specChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="开始售卖时间" required>
					<uni-datetime-picker type="date" :clear-icon="false" v-model="formData.sold_start_time"
						@change="maskClick1" />
				</uni-forms-item>
				<uni-forms-item label="结束售卖时间" required>
					<uni-datetime-picker type="date" :clear-icon="false" v-model="formData.sold_end_time"
						@change="maskClick2" />
				</uni-forms-item>
				<!-- <uni-forms-item label="使用规则" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.notification.title"></u--input>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.notification.content"
						maxlength="38"></u--input>
				</uni-forms-item> -->
				<!-- <uni-forms ref="form" label-position="top"> -->
				<uni-forms-item label="展示图片:">
					<u-upload :fileList="formData.image_list" @afterRead="afterRead" @delete="deletePic"
						uploadIcon="plus" name="1" :maxCount="9" multiple></u-upload>
				</uni-forms-item>
				<!-- </uni-forms> -->
				<!-- <uni-forms-item label="菜品图片">
					<u-upload :fileList="formData.dishes_image_list" @afterRead="afterRead" @delete="deletePic"
						uploadIcon="plus" name="2" :maxCount="3" multiple></u-upload>
				</uni-forms-item>
				<uni-forms-item label="环境图片">
					<u-upload :fileList="formData.environment_image_list" @afterRead="afterRead" @delete="deletePic"
						uploadIcon="plus" name="3" :maxCount="3" multiple></u-upload>
				</uni-forms-item> -->
			</uni-forms>
		</uni-card>
		<uni-card title="方案详情">
			<uni-forms ref="form" label-width="120">
				<uni-forms-item label="套餐名称" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.name"></u--input>
				</uni-forms-item>
				<uni-forms-item label="用餐人数" required>
					<view class="skuNumber">
						<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.num_one"
							type="number"></u--input>
						至
						<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.num_two"
							type="number"></u--input>
					</view>
				</uni-forms-item>
				<uni-forms-item label="商品总价（元）" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.menprice" type="digit"
						disabled></u--input>
				</uni-forms-item>
				<uni-forms-item label="团购价（元）" required>
					<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.tuanprice"
						type="digit"></u--input>
					<view style="font-size: 24rpx;color: red;">顾客实际支付金额不可大于商品总价</view>
				</uni-forms-item>
				<uni-forms-item label="包装费" required>
					<view class="package_price">
						<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.package_price"
							type="digit"></u--input>
						<button type="primary" size="mini" @click="chakan(0)" class="button">套餐详情</button>
					</view>
				</uni-forms-item>
				<u-popup :show="dialogShow" @close="closeDialog" mode="bottom" :closeable="true"
					:closeOnClickOverlay="false">
					<scroll-view class="demo-drawer__content" scroll-y="true" style="height: 60vh">
						<view class="neirong">
							<view>规格属性名称：{{ formData.sku.name }}</view>
							<view class="card c3 mb10 cshow" v-for="(val, i) in formData.sku.guigeList" :key="i"
								style="margin-top: 20px">
								<uni-forms ref="form" label-width="120">
									<uni-forms-item label="套餐分组名称" required label-width="120">
										<u--input placeholder="请输入内容" border="surround" v-model="val.tcname"></u--input>
									</uni-forms-item>
									<view class=""></view>
									<uni-forms-item label="选择" v-if="val.xuanxianglist.length > 1">
										<u-radio-group v-model="val.xuanxiang" @change="groupChange">
											<u-radio :customStyle="{marginBottom: '8px'}"
												v-for="item in val.xuanxianglist" :key="item.value" :label="item.label"
												:name="item.value">
											</u-radio>
										</u-radio-group>
									</uni-forms-item>
									<uni-forms-item>
										<button type="warn" size="mini" @click="shanchutao(index, i)"
											class="button">删除</button>
									</uni-forms-item>
								</uni-forms>
								<view style="width: 100%;height: 1rpx;background-color: #00bcd4;margin: 40rpx 0 ;">
								</view>
								<view v-for="(item, iii) in val.taochaninfolist" :key="iii">
									<uni-forms ref="form" label-width="120">
										<uni-forms-item label="套餐名称" required label-width="120">
											<u--input placeholder="请输入内容" border="surround"
												v-model="item.tcmingcname"></u--input>
										</uni-forms-item>
										<uni-forms-item label="份数(份)" required>
											<u-number-box v-model="item.number" :min="0" controls-position="right" />
										</uni-forms-item>
										<uni-forms-item label="单价(元)" required>
											<u--input placeholder="请输入单价" border="surround" v-model="item.price"
												type="digit"></u--input>
										</uni-forms-item>
										<button type="warn" size="mini" @click="shanchutaofenzu(index, i, iii)"
											class="button">删除</button>
									</uni-forms>
									<view style="width: 100%;height: 1rpx;background-color: #00bcd4;margin: 40rpx 0 ;">
									</view>
								</view>
								<button style="margin-top: 20px" size="mini" type="primary"
									@click="tianjiatao(i)">添加套餐内容</button>
							</view>
							<button style="margin-top: 20px" @click="addtaocan" size="mini"
								type="primary">添加套餐分组</button>
							<view class="" style="display: flex;align-items: center;margin-top: 30rpx;">
								<button @click="quxiqao" type="default" class="buttonStyle">关闭</button>
								<button type="primary" style="z-index: 10000;" @click="beforeclose"
									class="buttonStyle">确定</button>
							</view>

						</view>
					</scroll-view>
				</u-popup>
				<uni-forms-item label="库存类型" required>
					<uni-data-checkbox v-model="formData.sku.limit_type" :localdata="limit_type"
						@change="limitChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="库存数量" v-if="formData.sku.limit_type == 1">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.sku.stock_qty"
						type="number"></u--input>
				</uni-forms-item>
				<uni-forms-item label="虚拟销量">
					<u--input placeholder="请输入内容" border="surround" v-model="formData.sales_volume_other"
						type="number"></u--input>
				</uni-forms-item>
			</uni-forms>
		</uni-card>
		<uni-card title="规格组详情(选填)">
			<uni-forms-item label-width="150">
				<button type="primary" size="mini" @click="addJiajiaguige">添加多规格</button>
				<view style="margin-top: 10rpx;color: red;font-size: 24rpx;">注意:多规格如需要添加，不需要无需添加！</view>
			</uni-forms-item>
			<uni-forms-item>
				<view class="" v-for="(item, index) in formData.sku.add_data" :key="index">
					<view class="">
						<button type="default" size="mini" @click="addJiaPrice(index)">添加规格</button>
						<button type="warn" size="mini" @click="DeleteJiaguige(index)"
							style="margin-left: 30rpx;">删除规格</button>
						<uni-forms-item label="规格组名称" label-width="150">
							<u--input placeholder="请输入规格组名称" border="surround" v-model="item.name"></u--input>
						</uni-forms-item>
					</view>
					<u-divider></u-divider>
					<view class="" v-for="(val, i) in item.item_data" :key="i" style="margin-top: 20rpx;">
						<uni-forms-item label="规格名称">
							<u--input placeholder="请输入内容" border="surround" v-model="val.name"></u--input>
						</uni-forms-item>
						<uni-forms-item label="加价(元)">
							<u--input placeholder="请输入内容" border="surround" v-model="val.add_price"
								type="digit"></u--input>
						</uni-forms-item>
						<uni-forms-item label="数量">
							<u--input placeholder="请输入内容" border="surround" v-model="val.count" type="digit"></u--input>
						</uni-forms-item>
						<uni-forms-item label="重量">
							<u--input placeholder="请输入内容" border="surround" v-model="val.weight"
								type="digit"></u--input>
						</uni-forms-item>
						<view class="select">
							<uni-forms-item label="单位">
								<uni-data-select v-model="val.spec" :localdata="specArr" @change="unitChange"
									:clear="false"></uni-data-select>
							</uni-forms-item>
						</view>
						<uni-forms-item>
							<button type="warn" size="mini" @click="shanchujiajia(i, index)">删除</button>
						</uni-forms-item>
						<u-divider></u-divider>
					</view>
				</view>
			</uni-forms-item>
		</uni-card>
		<uni-card title="图文详情(选填)">
			<uni-forms-item label="图文详情">
				<button type="primary" size="mini" @click="addwen">添加</button>
			</uni-forms-item>
			<uni-forms-item>
				<view class="" v-for="(val, i) in formData.description_rich_text" :key="i" style="margin-top: 10rpx;">
					<u--textarea v-model="val.name" placeholder="请输入内容"></u--textarea>
					<u-upload :fileList="val.url" @afterRead="(event) => afterReadd(event, i)" :deletable='false'
						name="4" :maxCount="1"></u-upload>
					<button type="warn" size="mini" @click="tuwenshanchu(i)">删除</button>
				</view>
			</uni-forms-item>
		</uni-card>
		<uni-card title="售卖信息">
			<uni-forms ref="form" label-width="120">
				<uni-forms-item label="小程序跳转页面">
					<uni-data-checkbox v-model="formData.page_url_type" :localdata="page_url_type"
						@change="urlChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="适用门店" required>
					<view class="store">
						<button type="default" size="mini"
							@click="addStore(formData.id,formData.public_id)">适用门店</button>
						<view class="" v-if="this.formData.pois.length > 0">已选择<span
								style="color: red;">{{formData.pois.length}}</span>家门店</view>
					</view>
					<u-popup :show="addStoreShow" @close="close" mode="right" :closeable="true">
						<view class="prop">
							<view class="header" style="position: relative;">
								<u-search placeholder="请输入门店名称" v-model="storeName" shape="round" showAction
									@change="searchChange" @clear="searchClear" @custom="search"></u-search>
								<view class="" style="width: 100%;height: 10rpx;"></view>
								<uni-combox :candidates="province" placeholder="请选择地区" v-model="newQuery.province"
									emptyTips="这里啥都没有" @input="provinceSearch"></uni-combox>
								<button size="mini" type="primary" style="margin-top: 10rpx;"
									@click="getScPoiID">pio_ID批量正确匹配</button>
								<u-checkbox v-model="isAllChecked" @change="handleAllChange" label="全选"></u-checkbox>
							</view>
							<view class="content">
								<scroll-view scroll-y="true" style="height: 100vh">
									<uni-data-checkbox v-model="formData.pois" :localdata="mendianlist"
										@change="checkboxChange" :multiple="true" wrap>
									</uni-data-checkbox>
								</scroll-view>
							</view>
						</view>
					</u-popup>
				</uni-forms-item>
				<uni-forms-item label="售卖渠道">
					<uni-data-checkbox v-model="formData.show_channel" :localdata="show_channel"
						@change="channelChange"></uni-data-checkbox>
				</uni-forms-item>
				<uni-forms-item label="有效期">
					<uni-data-checkbox v-model="formData.apply_date.use_date_type" :localdata="use_date_type"
						@change="typeChange"></uni-data-checkbox>
					<view class="" style="display: flex;align-items: center;margin-top: 10rpx;">
						<u-number-box v-model="formData.apply_date.day_duration" @change="valChange"
							v-if="formData.apply_date.use_date_type == '2'"></u-number-box>
						<span style="margin-left: 5rpx;" v-if="formData.apply_date.use_date_type == '2'">天内有效</span>
						<uni-datetime-picker v-model="formData.apply_date.use_date" type="daterange" @change="maskClick"
							v-if="formData.apply_date.use_date_type == '1'" />
						<span style="margin-left: 5rpx;" v-if="formData.apply_date.use_date_type == '1'">天内有效</span>
					</view>
					<view class="" style="margin-top: 10rpx;color: #9ca2aa;font-size: 24rpx;">
						默认为360天，有效期最大支持7200天（约等于20年），请保证有效期不超过7200天</view>
				</uni-forms-item>
			</uni-forms>
			<view class="footer">
				<u-button text="确定" type="primary" v-if="addbmendianStatus == 1" @click="save">保存</u-button>
				<u-button text="确定" type="primary" v-if="addbmendianStatus == 2" @click="edit">确定</u-button>
			</view>
		</uni-card>
	</view>
</template>

<script>
	import {
		mapState,
	} from 'vuex'
	import config from '@/custom/config.js';
	import site from '@/custom/siteroot.js';
	import COS from 'cos-wx-sdk-v5';
	import CryptoJS from 'crypto-js';
	export default {
		data() {
			return {
				id: '',
				cos: null, // COS SDK 实例
				addbmendianStatus: '',
				formData: {
					public_id: '',
					product_name: '',
					tuan_dy_product_id: '',
					class_id: '',
					product_type: 14,
					category_id_one: '',
					pois: [],
					category_id_two: '',
					category_id_three: '',
					delivery_method: [],
					product_spec: 0,
					sold_start_time: '',
					sold_end_time: '',
					settle_type: 1,
					notification: {
						title: '',
						content: ''
					},
					image_list: [],
					dishes_image_list: [],
					environment_image_list: [],
					page_url_type: 1,
					show_channel: 1,
					sku: {
						add_data: [],
						name: '',
						num_one: 1,
						num_two: 2,
						menprice: 0,
						tuanprice: 0,
						package_price: 0,
						limit_type: 1,
						stock_qty: 1000,
						guigeList: [{
							tcname: '',
							xuanxianglist: [],
							xuanxiang: 1,
							taochaninfolist: [{
								tcmingcname: '',
								number: 0,
								price: 0,
							}, ],
						}, ],
					},
					sales_volume_other: '',
					apply_date: {
						use_date_type: 2,
						day_duration: 360,
						use_date: []
					},
					description_rich_text: [{
						name: '',
						url: [],
					}, ],
				},
				classfiyArr: [],
				category: '',
				product_type: [{
					text: "外卖",
					value: 14
				}],
				delivery_method: [{
						text: "立即配送",
						value: '1'
					},
					{
						text: "先囤后约",
						value: '2'
					}
				],

				product_spec: [{
						text: "套餐商品",
						value: 0
					},
					{
						text: "单商品",
						value: 1
					}
				],
				description_rich_text: [{
					name: '',
					url: [],
				}, ],
				page_url_type: [{
						text: "首页",
						value: 0
					},
					{
						text: "详情页",
						value: 1
					}
				],
				limit_type: [{
						text: "有限库存",
						value: 1
					},
					{
						text: "无限库存",
						value: 2
					}
				],
				addStoreShow: false,
				show_channel: [{
						text: "全渠道",
						value: 1
					},
					{
						text: "仅直播间",
						value: 2
					}
				],
				use_date_type: [{
						text: "指定天数",
						value: "2"
					},
					{
						text: "指定日期",
						value: "1"
					}
				],
				limitType: [{

				}],
				storeName: '',
				newQuery: {
					id: '',
					product_id: '',
					province: ""
				},
				mendianlist: [],
				isAllChecked: false,
				province: ["北京市",
					"天津市",
					"上海市",
					"重庆市",
					"河北省",
					"山西省",
					"台湾省",
					"陕西省",
					"陕南省",
					"吉林省",
					"黑龙江省",
					"江苏省",
					"浙江省",
					"安徽省",
					"福建省",
					"江西省",
					"山东省",
					"河南省",
					"湖北省",
					"湖南省",
					"广东省",
					"广西壮族自治区",
					"海南省",
					"四川省",
					"贵州省",
					"云南省",
					"西藏自治区",
					"陕西省",
					"甘肃省",
					"青海省",
					"宁夏回族自治区",
					"新疆维吾尔自治区",
					"内蒙古自治区"
				],
				addAndEditStatus: 0,
				range1: [],
				range2: [],
				range3: [],
				hexList: [],
				category_id: 0,
				dialogShow: false,
				xuanxiangArr: [],
				zuidiprice: 0,
				specArr: [{
						value: '毫升',
						text: '毫升',
					},
					{
						value: '升',
						text: '升',
					},
					{
						value: '克',
						text: '克',
					},
					{
						value: '千克',
						text: '千克',
					},
					{
						value: '两',
						text: '两',
					},
					{
						value: '斤',
						text: '斤',
					},
					{
						value: '份',
						text: '份',
					},
					{
						value: '个',
						text: '个',
					},
					{
						value: '杯',
						text: '杯',
					},
				]
			}
		},
		mounted() {
			// 初始化 COS SDK
			this.initCOS();
		},
		computed: {
			...mapState({
				menus: state => state.menus,
			}),
		},
		methods: {
			initCOS() {
				this.beg.request({
					url: '/admin/Cos/refreshToken',
					method: 'get',
				}).then(res => {
					// 获取临时密钥
					const {
						tmpSecretId,
						tmpSecretKey,
						sessionToken,
						startTime,
						expiredTime
					} = res.data;
					this.cos = new COS({
						getAuthorization: (options, callback) => {
							callback({
								TmpSecretId: tmpSecretId,
								TmpSecretKey: tmpSecretKey,
								SecurityToken: sessionToken,
								StartTime: startTime,
								ExpiredTime: expiredTime,
							});
						},
					});
				}).catch(error => {
					console.error('获取临时密钥失败:', error);
				});
			},
			getCategory() {
				this.loading = true
				this.beg.request({
					url: '/admin/product.ProductClass/index',
					method: 'post',
					data: {
						page: 1,
						limit: 300,
						is_deleted: 0
					}
				}).then((res) => {
					var classfiy = []
					res.data.data.forEach(i => {
						classfiy.push({
							value: i.id,
							text: i.name
						})
					})
					this.classfiyArr = classfiy
					this.loading = false
				})
			},
			// 商品类型
			statusChange(e) {
				this.formData.product_type = e.detail.value
			},
			// 配送方式
			deliverChange(e) {
				this.formData.delivery_method = e.detail.value
			},
			limitChange(e) {
				this.formData.sku.limit_type = e.detail.value
			},
			// 商品规格
			specChange(e) {
				this.formData.product_spec = e.detail.value
			},
			// 售卖时间
			maskClick1(e) {
				this.formData.sold_start_time = e
			},
			maskClick2(e) {
				this.formData.sold_end_time = e
			},
			deletePic(event) {
				if (event.name == '1') {
					this.formData.image_list.splice(event.index, 1)
				} else if (event.name == '2') {
					this.formData.dishes_image_list.splice(event.index, 1)
				} else if (event.name == '3') {
					this.formData.environment_image_list.splice(event.index, 1)
				}
			},
			async afterRead(event) {
				let lists = [].concat(event.file)
				if (event.name == '1') {
					let fileListLen = this.formData.image_list.length
					lists.map((item) => {
						this.formData.image_list.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.image_list[fileListLen]
						this.formData.image_list.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				} else if (event.name == '2') {
					let fileListLen = this.formData.dishes_image_list.length
					lists.map((item) => {
						this.formData.dishes_image_list.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.dishes_image_list[fileListLen]
						this.formData.dishes_image_list.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				} else if (event.name == '3') {
					let fileListLen = this.formData.environment_image_list.length
					lists.map((item) => {
						this.formData.environment_image_list.push({
							...item,
							status: 'uploading',
							message: '上传中'
						})
					})
					for (let i = 0; i < lists.length; i++) {
						const result = await this.handleFileInUploading(lists[i])
						let item = this.formData.environment_image_list[fileListLen]
						this.formData.environment_image_list.splice(fileListLen, 1, Object.assign(item, {
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						}))
						fileListLen++;
					}
				}
			},
			handleFileInUploading(event) {
				return new Promise((resolve, reject) => {
					const that = this
					const filePath = event.url
					const str = filePath.substr(filePath.lastIndexOf('/') + 1)
					const sha1Hash = CryptoJS.SHA1(str).toString();
					const fileName = '/storage/default/' + this.getCurrentDate() + '/' + str
					that.cos.uploadFile({
						Bucket: 'douyin-1325951894',
						Region: 'ap-beijing',
						Key: fileName,
						FilePath: filePath,
						SliceSize: 1024 * 1024 * 5,
						onFileFinish: function(err, data, options) {
							const fileUrl = '/' + options.Key
							that.beg.request({
								url: '/admin/Cos/callback',
								method: 'POST',
								data: {
									url: fileUrl,
									name: fileName,
									size: event.size,
									type: event.type,
									sha1: sha1Hash,
								},
							}).then(res => {
								if (res.code == 1) {
									setTimeout(() => {
										resolve(data)
									}, 500)
								}
							})
						},
					}, function(err, data, options) {
						// console.log(data,options)
					});
				})
			},
			// 图文详情
			async afterReadd(event, index) {
				const file = event.file; // 获取文件信息
				const fileName = `prefix-${Date.now()}-${Math.random()}`;
				const fileList = this.formData.description_rich_text[index].url;
				fileList.push({
					...file,
					status: 'uploading',
					message: '上传中'
				});
				const result = await this.handleFileInUploading2(file, index);
				const fileUrl = '/' + fileName;
				const updatedFileList = fileList.map((item) => {
					if (item.name === file.name) {
						return {
							...item,
							status: 'success',
							message: '',
							url: result.headers.location,
							src: result.Location,
						};
					}
					return item;
				});

				// 更新 formData
				this.$set(this.formData.description_rich_text, index, {
					...this.formData.description_rich_text[index],
					url: updatedFileList,
				});
			},
			handleFileInUploading2(file, index) {
				return new Promise((resolve, reject) => {
					const that = this
					const filePath = file.url;
					const str = filePath.substr(filePath.lastIndexOf('/') + 1);
					const sha1Hash = CryptoJS.SHA1(str).toString();
					const fileName = '/storage/default/' + that.getCurrentDate() + '/' + str;

					that.cos.uploadFile({
						Bucket: 'douyin-1325951894',
						Region: 'ap-beijing',
						Key: fileName,
						FilePath: filePath,
						SliceSize: 1024 * 1024 * 5,
						onFileFinish: function(err, data, options) {
							const fileUrl = '/' + options.Key;
							that.beg.request({
								url: '/admin/Cos/callback',
								method: 'POST',
								data: {
									url: fileUrl,
									name: fileName,
									size: file.size,
									type: file.type,
									sha1: sha1Hash,
								},
							}).then(res => {
								if (res.code == 1) {
									setTimeout(() => {
										resolve(data);
									}, 500);
								}
							});
						},
					}, function(err, data, options) {});
				});
			},
			getCurrentDate() {
				const now = new Date();
				const year = now.getFullYear();
				const month = (now.getMonth() + 1).toString().padStart(2, '0');
				const day = now.getDate().toString().padStart(2, '0');
				return year.toString() + month + day;
			},
			// 小程序跳转页面
			urlChange(e) {
				this.formData.page_url_type = e.detail.value
			},
			close() {
				this.addStoreShow = false
			},
			// 售卖渠道
			channelChange(e) {
				this.formData.show_channel = e.detail.value
			},
			// 有效期
			typeChange(e) {
				this.formData.apply_date.use_date_type = e.detail.value
			},
			closeDialog() {
				this.dialogShow = false
			},
			// 计算价格
			jisuan() {
				//计算价格
				let zaiArr = new Array()

				for (let i = 0; i < this.formData.sku.guigeList.length; i++) {
					//排序
					let arr = this.formData.sku.guigeList[i].taochaninfolist.sort((a, b) => b.number - a.number)
					zaiArr.push({
						xuanxiang: this.formData.sku.guigeList[i].xuanxiang,
						arr: arr,
					})
				}
				let numpiice = 0
				zaiArr.forEach((v) => {
					for (let p = 0; p < v.xuanxiang; p++) {
						numpiice += v.arr[p].price * v.arr[p].number
					}
				})
				//最低价
				let zaiDiArr = new Array()
				for (let i = 0; i < this.formData.sku.guigeList.length; i++) {
					//排序
					let arrDi = this.formData.sku.guigeList[i].taochaninfolist.sort((a, b) => a.number - b.number)
					zaiDiArr.push({
						xuanxiang: this.formData.sku.guigeList[i].xuanxiang,
						arr: arrDi,
					})
				}
				//计算最低
				let numDipiice = 0
				zaiDiArr.forEach((v) => {
					for (let p = 0; p < v.xuanxiang; p++) {
						numDipiice += v.arr[0].price * v.arr[0].number
					}
				})
				this.zuidiprice = numDipiice.toFixed(2)
				this.formData.sku.menprice = numpiice.toFixed(2)
			},
			// 搜索
			searchChange(val) {
				if (val == '') {
					this.newQuery.province = ""
					this.getStoreList()
				}
			},
			searchClear(val) {
				this.newQuery.province = ""
				this.getStoreList()
			},
			search() {
				if (this.storeName != '') {
					const results = this.mendianlist.filter((item) => item.text.includes(this.storeName))
					this.mendianlist = results
				} else {
					this.newQuery.province = ""
					this.getStoreList()
				}
			},
			// 门店列表
			getStoreList() {
				uni.showLoading()
				this.beg.request({
					url: '/admin/public_product.PublicProduct/get_all_store_v2',
					method: "post",
					data: this.newQuery
				}).then(res => {
					if (res.code == 1) {
						uni.hideLoading()
						var arr = res.data
						this.mendianlist = JSON.parse(JSON.stringify(arr).replaceAll("store_name", "text")
							.replaceAll("dy_poi_id", "value"))
					} else {
						uni.hideLoading()
					}
				})
			},
			// 包装费
			shanchutao(index, i) {
				if (this.formData.sku.guigeList.length == 1) {
					return
				}
				this.formData.sku.guigeList.splice(i, 1)
			},
			shanchutaofenzu(index, i, iii) {
				if (this.formData.sku.guigeList[i].taochaninfolist.length == 1) {
					return
				}
				this.formData.sku.guigeList[i].xuanxianglist.splice(this.formData.sku.guigeList[i].xuanxianglist.length -
					1, 1)
				let num = this.formData.sku.guigeList[i].xuanxianglist.length
				this.formData.sku.guigeList[i].xuanxianglist.forEach((v) => {
					v.label = num + '选' + v.value
				})
				this.formData.sku.guigeList[i].xuanxiang = this.formData.sku.guigeList[i].xuanxianglist.length
				this.formData.sku.guigeList[i].taochaninfolist.splice(iii, 1)
			},
			tianjiatao(i) {
				if (this.formData.product_spec == 1) {
					if (this.formData.sku.guigeList[0].taochaninfolist.length >= 5) {
						uni.$u.toast('单商品，规则项最多设置5组！')
						return
					}
				}
				this.formData.sku.guigeList[i].taochaninfolist.push({
					tcmingcname: '',
					number: 0,
					price: 0,
				})
				if (this.formData.sku.guigeList[i].taochaninfolist.length > 1) {
					this.formData.sku.guigeList[i].xuanxianglist = []
					let arr = new Array()
					let changdu = this.formData.sku.guigeList[i].taochaninfolist.length
					for (let i = 0; i < changdu; i++) {
						arr.push({
							value: i + 1,
							label: changdu + '选' + (i + 1),
						})
					}
					this.formData.sku.guigeList[i].xuanxianglist = arr
					this.formData.sku.guigeList[i].xuanxiang = 1
				}
			},
			addtaocan() {
				if (this.formData.product_spec == 1) {
					if (this.formData.sku.guigeList.length >= 1) {
						uni.$u.toast('单商品，规则套餐最多设置1组！')
						return
					}
				}

				this.formData.sku.guigeList.push({
					tcname: '',
					xuanxianglist: [],
					xuanxiang: 1,
					taochaninfolist: [{
						tcmingcname: '',
						number: 0,
						price: 0,
					}, ],
				})
			},
			addStore(e, val) {
				this.newQuery.id = val
				this.newQuery.product_id = this.id
				this.addStoreShow = true
				this.getStoreList()
			},
			quxiqao() {
				if (this.formData.sku.guigeList[0].tcname == '') {
					this.formData.sku.status = false
				}
				this.dialogShow = false
			},
			beforeclose() {
				for (let i = 0; i < this.formData.sku.guigeList.length; i++) {
					if (this.formData.sku.guigeList[i].tcname == '') {
						uni.$u.toast('套餐分组名称为空，请检查是否填写')
						return
					}
				}
				for (let i = 0; i < this.formData.sku.guigeList.length; i++) {
					for (let o = 0; o < this.formData.sku.guigeList[i].taochaninfolist.length; o++) {
						if (this.formData.sku.guigeList[i].taochaninfolist[o].tcmingcname == '') {
							uni.$u.toast('套餐名称为空，请检查是否填写')
							return
						}
						if (this.formData.sku.guigeList[i].taochaninfolist[o].number == '') {
							uni.$u.toast('份数为空，请检查是否填写')
							return
						}
						if (this.formData.sku.guigeList[i].taochaninfolist[o].price == '') {
							uni.$u.toast('单价为空，请检查是否填写')
							return
						}
					}
				}
				this.jisuan()
				this.formData.sku.menpriceStatus = false
				this.formData.sku.status = true
				this.dialogShow = false
			},
			checkboxChange(e, index) {
				this.formData.pois = e.detail.value
				if (this.formData.pois.length > 0 && this.formData.pois.length == this.mendianlist.length) {
					this.allChecked = true;
				} else {
					this.allChecked = false;
				}
			},

			// 全选
			handleAllChange(e) {
				if (e) {
					const newArr = this.mendianlist.map((item) => {
						return item.value;
					})
					this.formData.pois = newArr
					this.isAllChecked = true
				} else {
					this.formData.pois = []
					this.isAllChecked = false
				}
			},
			provinceSearch(e) {
				this.newQuery.province = e
				this.getStoreList()
			},
			// pio_ID批量正确匹配
			getScPoiID() {
				let pois = [];
				this.mendianlist.forEach((item) => {
					this.formData.pois.forEach((v) => {
						if (item.dy_poi_id == v) {
							pois.push(v);
						}
					})
				})
				this.formData.pois = pois;
				uni.showToast({
					title: "操作成功",
					icon: "success"
				})
			},
			// 有效期
			valChange(e) {
				this.formData.apply_date.day_duration = e.value
			},
			maskClick(e) {
				this.formData.apply_date.use_date = e
			},
			// 查看
			chakan(i) {
				if (this.addAndEditStatus == 1) {
					this.dialogShow = true
					return
				}
				if (this.formData.sku.guigeList[0].tcname != '') {
					this.dialogShow = true
					return
				}
				this.formData.sku.guigeList = [{
					tcname: '',
					xuanxianglist: [],
					xuanxiang: 1,
					taochaninfolist: [{
						tcmingcname: '',
						number: '',
						price: '',
					}, ],
				}, ]
				this.dialogShow = true
			},
			save() {
				if (this.formData.product_name == '') {
					uni.$u.toast('请填写商品名称')
					return;
				}
				let xianame = '虾'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				xianame = '海鲜'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				xianame = 'xia'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				if (this.formData.class_id == '') {
					uni.$u.toast('请选择商品分类')
					return;
				}
				if (this.formData.category_id_one == '') {
					uni.$u.toast('请选择抖音品类')
					return;
				}
				if (this.range2.length > 0 && this.formData.category_id_two == '') {
					uni.$u.toast('请选择抖音品类')
					return;
				}
				if (this.range3.length > 0 && this.formData.category_id_three == '') {
					uni.$u.toast('请选择抖音品类')
					return;
				}
				// if (this.formData.product_type == 0 || this.formData.product_type == '') {
				// 	uni.$u.toast('请选择商品类型')
				// 	return;
				// }
				if (this.formData.delivery_method.length == 0) {
					uni.$u.toast('请选择配送方式')
					return;
				}
				if (this.formData.sold_start_time == '') {
					uni.$u.toast('请选择开始售卖时间')
					return;
				}
				if (this.formData.sold_end_time == '') {
					uni.$u.toast('请选择结束售卖时间')
					return;
				}
				if (this.formData.sku.name == '') {
					uni.$u.toast('请填写套餐名称')
					return;
				}
				if (this.formData.sku.num_one == '' || this.formData.sku.num_two == '') {
					uni.$u.toast('请填写用餐人数')
					return;
				}
				// if (this.formData.sku.menprice == '') {
				// 	uni.$u.toast('请填写商品总价')
				// 	return;
				// }
				if (this.formData.sku.tuanprice == '') {
					uni.$u.toast('请填写团购价')
					return;
				}
				if (this.formData.sku.package_price == '') {
					uni.$u.toast('请填写包装费')
					return;
				}
				if (this.formData.sku.limit_type == '') {
					uni.$u.toast('请选择库存类型')
					return;
				}
				if (this.formData.pois.length < 1) {
					uni.$u.toast('请选择适用门店')
					return;
				}
				//判断套餐
				if (this.formData.sku.guigeList[0].taochaninfolist[0].tcmingcname == '') {
					uni.$u.toast('请设置规格内的套餐')
					return;
				}
				if (this.formData.product_spec == 1) {
					if (this.formData.sku.guigeList.length > 1) {
						uni.$u.toast('规格内的套餐错误')
						return;
					}
				}
				if (this.formData.sku.num_one == 0 || this.formData.sku.num_two == 0 || this.formData.sku.menprice == 0 ||
					this.formData.sku.tuanprice == 0) {
					uni.$u.toast('请检查套餐（用餐人数，门市价，团购价），不能为0')
					return
				}
				// if (this.formData.notification.content == '') {
				// 	uni.$u.toast('使用规则内容不能为空')
				// 	return
				// }
				if (this.formData.apply_date.use_date_type == '1') {
					let strtTime = new Date(this.formData.apply_date.use_date[0]).getTime()
					let soldstrtTime = new Date(this.formData.sold_start_time).getTime()
					if (strtTime < soldstrtTime) {
						uni.$u.toast('有效期开始时间不能早于商品开始售卖时间')
						return
					}
					this.formData.apply_date.use_start_date = this.formData.apply_date.use_date[0]
					this.formData.apply_date.use_end_date = this.formData.apply_date.use_date[1]
				}
				if (this.formData.image_list.length < 2) {
					uni.$u.toast('展示图片至少2张')
					return
				}
				// if (this.formData.environment_image_list.length < 2) {
				// 	uni.$u.toast('环境图片至少2张')
				// 	return
				// }
				// if (this.formData.dishes_image_list.length < 2) {
				// 	uni.$u.toast('菜品图片至少2张')
				// 	return
				// }
				const logoSrcs = [];
				this.formData.image_list.forEach((item) => {
					const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
					logoSrcs.push(afterCom)
				});
				this.formData.image_list = logoSrcs;
				this.formData.dishes_image_list = logoSrcs
				this.formData.environment_image_list = logoSrcs
				// const logoSrcs2 = [];
				// this.formData.dishes_image_list.forEach((item) => {
				// 	const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
				// 	logoSrcs2.push(afterCom)
				// });
				// this.formData.dishes_image_list = logoSrcs2;
				// const logoSrcs3 = [];
				// this.formData.environment_image_list.forEach((item) => {
				// 	const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
				// 	logoSrcs3.push(afterCom)
				// });
				// this.formData.environment_image_list = logoSrcs3;
				this.formData.description_rich_text.forEach((item) => {
					const itemTuwenImg = [];
					item.url.forEach(v => {
						const afterCom = v.src.substring(v.src.lastIndexOf('.com') + 4);
						itemTuwenImg.push(afterCom);
					});
					item.url = itemTuwenImg;
				});
				let jaiStatus = false;
				//组装加价
				this.formData.sku.add_data.forEach((vv) => {
					if (vv.name == '') {
						jaiStatus = true;
						return;
					}
					vv.item_data.forEach((v) => {
						if (v.count == 0 || v.name == '' || v.weight == '' || v.spec == '') {
							jaiStatus = true;
							return;
						}
					})
				})
				if (jaiStatus) {
					uni.$u.toast('加价信息错误(请检查是否填写正确)')
					return;
				}
				this.formData.sku.add_data.forEach((vv) => {
					if (vv.xuanxianglist.length == 0) {
						vv.total_count = 1;
					} else {
						vv.total_count = vv.xuanxianglist.length;
					}
					if (vv.xuanxiang == 0) {
						vv.option_count = 1;
					} else {
						vv.option_count = Number(vv.xuanxiang);
					}

					vv.item_data.forEach((vvv) => {
						vvv.add_price = vvv.add_price * 100;
					})
				})
				if (this.formData.sku.limit_type != 1) {
					this.formData.sku.stock_qty = 9999999;
				}
				this.beg.request({
					url: '/admin/product.Product/add',
					method: 'post',
					data: this.formData,
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast('添加成功')
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							})
						}, 1000);
					} else {
						uni.$u.toast('添加失败')
					}
				})
			},
			edit() {
				if (this.formData.product_name == '') {
					uni.$u.toast('请填写商品名称')
					return;
				}
				let xianame = '虾'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				xianame = '海鲜'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				xianame = 'xia'
				if (this.formData.product_name.includes(xianame)) {
					uni.$u.toast(
						'因小龙虾、海鲜类商品履约问题频发，为保障食品安全和消费者权益，自即日起平台不再支持所有外卖业务小龙虾、海鲜、海鲜火锅、海鲜自助类商品的引入和商品创建。目前在售上述类目的商家，自【2024年4月11日】起小龙虾和海鲜类目不再支持售卖。如有任何问题可咨询抖音生活服务热线【4001566000】，感谢您的理解与支持。。'
					)
					return
				}
				if (this.formData.class_id == '') {
					uni.$u.toast('请选择商品分类')
					return;
				}
				if (this.formData.category_id_one == '') {
					uni.$u.toast('请选择抖音品类')
					return;
				}
				// if (this.formData.product_type == 0 || this.formData.product_type == '') {
				// 	uni.$u.toast('请选择商品类型')
				// 	return;
				// }
				if (this.formData.delivery_method.length == 0) {
					uni.$u.toast('请选择配送方式')
					return;
				}
				if (this.formData.sold_start_time == '') {
					uni.$u.toast('请选择开始售卖时间')
					return;
				}
				if (this.formData.sold_end_time == '') {
					uni.$u.toast('请选择结束售卖时间')
					return;
				}
				if (this.formData.sku.name == '') {
					uni.$u.toast('请填写套餐名称')
					return;
				}
				if (this.formData.sku.num_one == '' || this.formData.sku.num_two == '') {
					uni.$u.toast('请填写用餐人数')
					return;
				}
				// if (this.formData.sku.menprice == '') {
				// 	uni.$u.toast('请填写商品总价')
				// 	return;
				// }
				if (this.formData.sku.tuanprice == '') {
					uni.$u.toast('请填写团购价')
					return;
				}
				if (this.formData.sku.package_price == '') {
					uni.$u.toast('请填写包装费')
					return;
				}
				if (this.formData.sku.limit_type == '') {
					uni.$u.toast('请选择库存类型')
					return;
				}
				if (this.formData.pois.length < 1) {
					uni.$u.toast('请选择适用门店')
					return;
				}
				//判断套餐
				if (this.formData.sku.guigeList[0].taochaninfolist[0].tcmingcname == '') {
					uni.$u.toast('请设置规格内的套餐')
					return
				}
				if (this.formData.product_spec == 1) {
					if (this.formData.sku.guigeList.length > 1) {
						uni.$u.toast('规格内的套餐错误')
						return
					}
				}
				if (this.formData.sku.num_one == 0 || this.formData.sku.num_two == 0 || this.formData.sku.menprice == 0 ||
					this.formData.sku.tuanprice == 0) {
					uni.$u.toast('请检查套餐（用餐人数，门市价，团购价），不能为0')
					return
				}
				// if (this.formData.notification.content == '') {
				// 	uni.$u.toast('使用规则内容不能为空')
				// 	return
				// }
				if (this.formData.apply_date.use_date_type == '1') {
					let strtTime = new Date(this.formData.apply_date.use_date[0]).getTime()
					let soldstrtTime = new Date(this.formData.sold_start_time).getTime()
					if (strtTime < soldstrtTime) {
						uni.$u.toast('有效期开始时间不能早于商品开始售卖时间')
						return
					}
					this.formData.apply_date.use_start_date = this.formData.apply_date.use_date[0]
					this.formData.apply_date.use_end_date = this.formData.apply_date.use_date[1]
				}
				if (this.formData.image_list.length < 2) {
					uni.$u.toast('展示图片至少2张')
					return
				}
				// if (this.formData.environment_image_list.length < 2) {
				// 	uni.$u.toast('环境图片至少2张')
				// 	return
				// }
				// if (this.formData.dishes_image_list.length < 2) {
				// 	uni.$u.toast('菜品图片至少2张')
				// 	return
				// }
				const logoSrcs = [];
				this.formData.image_list.forEach((item) => {
					const exists = item.src.includes('douyin');
					if (exists) {
						const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
						logoSrcs.push(afterCom)
					} else {
						logoSrcs.push(item.src);
					}
				});
				this.formData.image_list = logoSrcs;
				this.formData.dishes_image_list = logoSrcs
				this.formData.environment_image_list = logoSrcs
				// const logoSrcs2 = [];
				// this.formData.dishes_image_list.forEach((item) => {
				// 	const exists = item.src.includes('douyin');
				// 	if (exists) {
				// 		const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
				// 		logoSrcs2.push(afterCom)
				// 	} else {
				// 		logoSrcs2.push(item.src);
				// 	}
				// });
				// this.formData.dishes_image_list = logoSrcs2;
				// const logoSrcs3 = [];
				// this.formData.environment_image_list.forEach((item) => {
				// 	const exists = item.src.includes('douyin');
				// 	if (exists) {
				// 		const afterCom = item.src.substring(item.src.lastIndexOf('.com') + 4);
				// 		logoSrcs3.push(afterCom)
				// 	} else {
				// 		logoSrcs3.push(item.src);
				// 	}
				// });
				// this.formData.environment_image_list = logoSrcs3;
				this.formData.description_rich_text.forEach((item) => {
					const itemTuwenImg = [];
					item.url.forEach(v => {
						const exists = v.src.includes('douyin');
						if (exists) {
							const afterCom = v.src.substring(v.src.lastIndexOf('.com') + 4);
							itemTuwenImg.push(afterCom);
						} else {
							itemTuwenImg.push(v.src);
						}

					});
					item.url = itemTuwenImg;
				});
				let jaiStatus = false;
				//组装加价
				this.formData.sku.add_data.forEach((vv) => {
					if (vv.name == '') {
						jaiStatus = true;
						return;
					}
					vv.item_data.forEach((v) => {
						if (v.count == 0 || v.name == '' || v.weight == '' || v.spec == '') {
							jaiStatus = true;
							return;
						}
					})
				})
				if (jaiStatus) {
					uni.$u.toast('加价信息错误(请检查是否填写正确)')
					return;
				}
				this.formData.sku.add_data.forEach((vv) => {
					if (vv.xuanxianglist.length == 0) {
						vv.total_count = 1;
					} else {
						vv.total_count = vv.xuanxianglist.length;
					}
					if (vv.xuanxiang == 0) {
						vv.option_count = 1;
					} else {
						vv.option_count = Number(vv.xuanxiang);
					}
					vv.item_data.forEach((vvv) => {
						vvv.add_price = vvv.add_price * 100
					});
				})
				if (this.formData.sku.limit_type != 1) {
					this.formData.sku.stock_qty = 9999999;
				}
				this.beg.request({
					url: '/admin/product.Product/edit',
					method: 'post',
					data: this.formData,
				}).then(res => {
					if (res.code == 1) {
						uni.$u.toast('编辑成功')
						setTimeout(function() {
							uni.navigateBack({
								delta: 1
							})
						}, 1000);

					} else {
						uni.$u.toast('编辑失败')
					}
				})
			},
			classChange(e) {
				this.formData.class_id = e
			},
			selectChange1(e) {
				this.formData.category_id_one = e
				this.getpinleiList2()
			},
			selectChange2(e) {
				this.formData.category_id_two = e
				this.getpinleiList3()

			},
			selectChange3(e) {
				this.formData.category_id_three = e
			},
			addwen() {
				const newItemId = Date.now() + Math.random().toString(16).slice(2);
				this.formData.description_rich_text.push({
					name: '',
					url: [],
					id: newItemId
				});
			},
			tuwenshanchu(index) {
				this.formData.description_rich_text.splice(index, 1)
			},
			/**
			 * 生成全球唯一标识
			 * @returns uuid
			 */
			uuid() {
				let uuid = ''
				for (let i = 1; i <= 36; i++) {
					if (i === 9 || i === 14 || i === 19 || i === 24) {
						uuid += '-'
					} else if (i === 15) {
						uuid += 4
					} else if (i === 20) {
						uuid += this.hexList[(Math.random() * 4) | 8]
					} else {
						uuid += this.hexList[(Math.random() * 16) | 0]
					}
				}
				return uuid
			},
			getpinleiList() {
				this.beg.request({
					url: '/admin/select/get_dy_product_select',
					method: 'post',
					data: {
						category_id: this.category_id
					}
				}).then(res => {
					if (res.code == 1) {
						var arr = []
						res.data.forEach(item => {
							arr.push({
								value: item.category_id,
								text: item.name
							})

						})
						this.range1 = arr
					}
				})
			},
			getpinleiList2() {
				this.beg.request({
					url: '/admin/select/get_dy_product_select',
					method: 'post',
					data: {
						category_id: this.formData.category_id_one
					}
				}).then(res => {
					if (res.code == 1) {
						var arr = []
						if (res.data.length == 0) {
							this.formData.category_id_two = ''
						}
						res.data.forEach(item => {
							arr.push({
								value: item.category_id,
								text: item.name
							})
						})
						this.range2 = arr
					}
				})
			},
			getpinleiList3() {
				this.beg.request({
					url: '/admin/select/get_dy_product_select',
					method: 'post',
					data: {
						category_id: this.formData.category_id_two
					}
				}).then(res => {
					if (res.code == 1) {
						if (res.data.length == 0) {
							this.formData.category_id_three = ''
						}
						var arr = []
						res.data.forEach(item => {
							arr.push({
								value: item.category_id,
								text: item.name
							})
						})
						this.range3 = arr
					}
				})
			},
			groupChange(e) {
				this.formData.sku.guigeList.forEach(e => {})
			},
			getInfoDetail() {
				uni.showLoading()
				this.beg.request({
					url: '/admin/product.Product/getProductInfo',
					method: 'post',
					data: {
						id: this.id
					}
				}).then(res => {
					if (res.code == 1) {
						if (res.data.delivery_method != '') {
							res.data.delivery_method = JSON.parse(res.data.delivery_method)
						}
						if (res.data.pois != '') {
							res.data.pois = JSON.parse(res.data.pois)
						}
						if (res.data.apply_date != '') {
							res.data.apply_date = JSON.parse(res.data.apply_date)
						}
						if (res.data.description_rich_text != '') {
							res.data.description_rich_text = JSON.parse(res.data.description_rich_text)
						}
						if (res.data.notification != '') {
							res.data.notification = JSON.parse(res.data.notification)
						}
						if (res.data.dishes_image_list != '') {
							res.data.dishes_image_list = JSON.parse(res.data.dishes_image_list)
						}
						if (res.data.environment_image_list != '') {
							res.data.environment_image_list = JSON.parse(res.data.environment_image_list)
						}
						if (res.data.image_list != '') {
							res.data.image_list = JSON.parse(res.data.image_list)
						}
						//处理sku
						res.data.sku.guigeList = JSON.parse(res.data.sku.specs)
						res.data.sku.name = res.data.sku.sku_name
						res.data.sku.menprice = res.data.sku.origin_amount
						res.data.sku.tuanprice = res.data.sku.actual_amount
						if (res.data.image_list.length > 0) {
							let arr = [];
							res.data.image_list.forEach((v) => {
								arr.push({
									url: site.siteimgroot +
										v,
									src: v
								});
							})
							res.data.image_list = arr;
						}
						if (res.data.dishes_image_list.length > 0) {
							let arr = [];
							res.data.dishes_image_list.forEach((v) => {
								arr.push({
									url: site.siteimgroot +
										v,
									src: v
								});
							})
							res.data.dishes_image_list = arr;
						}
						if (res.data.environment_image_list.length > 0) {
							let arr = [];
							res.data.environment_image_list.forEach((v) => {
								arr.push({
									url: site.siteimgroot +
										v,
									src: v
								});
							})
							res.data.environment_image_list = arr;
						}
						if (res.data.description_rich_text.length >
							0) {
							res.data.description_rich_text.forEach((val) => {
								let arr = [];
								val.url.forEach((item) => {
									arr.push({
										url: site.siteimgroot +
											val,
										src: item
									});
								});
								val.url = arr; // 更新每个项的 url 字段
							});
						}
						res.data.sku.guigeList.forEach(item => {
							item.xuanxianglist.forEach(val => {
								this.xuanxiangArr.push({
									value: val.value,
									text: val.label
								})
							})
						})
						if (!res.data.sku.add_data) {
							res.data.sku.add_data = [];
						} else {
							res.data.sku.add_data = JSON.parse(res.data.sku.add_data);
							res.data.sku.add_data.forEach((v) => {
								v.xuanxiang = Number(v.option_count);
								let arr = new Array()
								for (let i = 0; i < v.total_count; i++) {
									arr.push({
										value: i + 1,
										label: v.total_count + '选' + (i + 1),
									})
								}
								v.xuanxianglist = arr
								v.item_data.forEach((v) => {
									v.add_price = Number(v.add_price) / 100;
								})
							})
						}
						this.formData = res.data
						this.getpinleiList()
						this.getpinleiList2()
						this.getpinleiList3()
						uni.hideLoading()
						console.log(this.formData)
					}
				})
			},
			addJiajiaguige() {
				if (!Array.isArray(this.formData.sku.add_data)) {
					this.formData.sku.add_data = [];
				}
				this.formData.sku.add_data.push({
					name: '',
					total_count: 1,
					option_count: 1,
					xuanxiang: 1,
					xuanxianglist: [],
					item_data: [{
						add_price: 0,
						count: 1,
						name: '',
						weight: '',
						spec: ''
					}],
				});
			},
			// 增加规格
			addJiaPrice(index) {
				this.formData.sku.add_data[index].item_data.push({
					add_price: 0,
					count: 1,
					name: '',
					weight: '',
					spec: ''
				});
				if (this.formData.sku.add_data[index].item_data.length > 1) {
					this.formData.sku.add_data[index].xuanxianglist = []
					let arr = new Array()
					let changdu = this.formData.sku.add_data[index].item_data.length
					for (let i = 0; i < changdu; i++) {
						arr.push({
							value: i + 1,
							label: changdu + '选' + (i + 1),
						})
					}
					this.formData.sku.add_data[index].xuanxianglist = arr
					this.formData.sku.add_data[index].xuanxiang = 1
				}
			},
			DeleteJiaguige(index) {
				this.formData.sku.add_data.splice(index, 1);
			},
			shanchujiajia(i, index) {
				if (this.formData.sku.add_data[index].item_data.length == 0) {
					return
				}
				if (this.formData.sku.add_data[index].item_data.length == 1) {
					this.formData.sku.add_data.splice(index, 1);
				}
				this.formData.sku.add_data[index].item_data.splice(i, 1);
				this.formData.sku.add_data[index].xuanxianglist.splice(this.formData.sku.add_data[index].xuanxianglist
					.length -
					1, 1);
				let num = this.formData.sku.add_data[index].xuanxianglist.length;
				this.formData.sku.add_data[index].xuanxianglist.forEach((v) => {
					v.label = num + '选' + v.value
				})
				this.formData.sku.add_data[index].xuanxiang = this.formData.sku.add_data[index].xuanxianglist.length;
			},
			unitChange(e) {
				console.log(e)
			}
		},
		onLoad(option) {
			for (let i = 0; i <= 15; i++) {
				this.hexList[i] = i.toString(16)
			}
			if (option.stutas == 1) {
				this.addbmendianStatus = 1
				this.getCategory()
				this.getpinleiList()
			} else {
				this.getCategory()
				this.addbmendianStatus = 2
				this.id = option.id
				this.getInfoDetail()
			}
		}
	}
</script>

<style lang="scss" scoped>
	::v-deep .uni-forms-item.is-direction-left {
		align-items: center;
	}

	::v-deep .picker-label {
		font-size: 36rpx;
	}

	.skuNumber {
		display: flex;
		align-items: center;
	}

	.package_price {
		display: flex;
		align-items: center;

		.button {
			margin-left: 10rpx;
		}
	}

	.store {
		display: flex;
		align-items: center;
	}

	.header {
		width: 95%;
		margin: 0 auto;
		margin-top: 100rpx;
	}

	.content {
		margin-top: 30rpx;
		margin-left: 20rpx;
	}

	.footer {
		width: 62%;
		margin: 0 auto;
	}

	.demo-drawer__content {
		margin-top: 70rpx;

		.neirong {
			width: 93%;
			margin: 0 auto;
		}
	}

	.buttonStyle {
		width: 170rpx;
		height: 70rpx;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	::v-deep .u-radio-group--row {
		display: flex;
		flex-wrap: wrap;
		flex-direction: row;
		justify-content: space-between;
		align-items: flex-start;
	}

	::v-deep .u-upload {
		margin-top: 20rpx;
	}

	.select {
		/deep/.uni-select__selector {
			top: unset;
			bottom: calc(100% + 12px);
		}

		/deep/.uni-select__input-text {
			font-size: 14px;
			color: #7f7f7f;
		}

		/deep/.uni-select__input-placeholder {
			font-size: 14px;
			color: #7f7f7f;
		}

		/deep/.uni-popper__arrow {
			top: unset;
			bottom: -6px;
			transform: rotate(180deg);
		}

		/deep/.uni-popper__arrow::after {
			top: 0
		}
	}

	::v-deep .u-upload__wrap {
		width: 110%;
	}
</style>